export function buildTree(flatData: any[]): any[] {
    const map: { [key: number]: any } = {};
    const roots: any[] = [];
  
    // 将所有节点放入map中
    flatData.forEach(node => {
      map[node.id] = { ...node, children: [] };
    });
  
    // 构建树
    flatData.forEach(node => {
      if (node.pid !== undefined && map[node.pid]) {
        map[node.pid].children.push(map[node.id]);
      } else {
        roots.push(map[node.id]);
      }
    });
  
    return roots;
  }